{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1 align=\"center\">Welcome to SimpleITK Jupyter Notebooks</h1>\n",
    "\n",
    "\n",
    "## Newcomers to Jupyter Notebooks:\n",
    "1. We use two types of cells, code and markdown.\n",
    "2. To run a code cell, select it (mouse or arrow key so that it is highlighted) and then press shift+enter which also moves focus to the next cell or ctrl+enter which doesn't.\n",
    "3. Closing the browser window does not close the Jupyter server. To close the server, go to the terminal where you ran it and press ctrl+c twice.\n",
    "\n",
    "For additional details see the [Jupyter project documentation](https://jupyter.org/documentation) on Jupyter Notebook or JupyterLab.\n",
    "\n",
    "## SimpleITK Environment Setup\n",
    "\n",
    "Check that SimpleITK and auxiliary program(s) are correctly installed in your environment, and that you have the SimpleITK version which you expect (<b>requires network connectivity</b>).\n",
    "\n",
    "You can optionally download all of the data used in the notebooks in advance. This step is only necessary if you expect to run the notebooks without network connectivity."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following cell checks that all expected packages are installed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# check that all packages are installed (see requirements.txt file)\n",
    "required_packages <- c(\"SimpleITK\", \"rPython\", \"scatterplot3d\", \"tidyr\", \"ggplot2\", \"xtable\", \"purrr\")\n",
    "missing_packages <- required_packages[!unlist(lapply(required_packages, require, character.only = TRUE, quietly = TRUE))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "library(SimpleITK)\n",
    "\n",
    "source(\"downloaddata.R\")\n",
    "\n",
    "print(Version())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We expect that you have an external image viewer installed. The default viewer is <a href=\"https://fiji.sc/#download\">Fiji</a>. If you have another viewer (i.e. ITK-SNAP or 3D Slicer) you will need to set an environment variable to point to it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
   "collapsed": false,
   "simpleitk_error_allowed": "Exception in SITK"
   },
   "outputs": [],
   "source": [
    "# Retrieve an image from the network, read it and display using the external viewer. \n",
    "# The show method will also set the display window's title and by setting debugOn to TRUE, \n",
    "# will also print information with respect to the command it is attempting to invoke.\n",
    "# NOTE: The debug information is printed to the terminal from which you launched the notebook\n",
    "#       server.\n",
    "Show(ReadImage(fetch_data(\"SimpleITK.jpg\")), \"SimpleITK Logo\", debugOn=TRUE)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Download all of the data in advance if you expect to be working offline (may take a couple of minutes)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "fetch_data_all(file.path(\"..\",\"Data\"), file.path(\"..\",\"Data\",\"manifest.json\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.2.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
